package com.moonshineproject.atomic {
	import flash.events.FocusEvent;
	
	import mx.core.UIComponent;
	import mx.events.FocusRequestDirection;
	import mx.managers.IFocusManagerComponent;
 
	public class TabStopper extends UIComponent implements IFocusManagerComponent {
		public function TabStopper(isStart:Boolean) {
			super();
			tabIndex = (isStart) ? 1 : int.MAX_VALUE;
		}
		
		/**
		 * Immediately after a focus in event happens, the previous component is given the focus instead.
		 */
		// sdk 3.2 and later
		override protected function focusInHandler(event:FocusEvent):void {
			if (enabled) {
				var direction:String = (event.shiftKey) ? FocusRequestDirection.FORWARD : mx.events.FocusRequestDirection.BACKWARD;
				focusManager.moveFocus(direction);
			} else {
				direction = (!event.shiftKey) ? FocusRequestDirection.FORWARD : mx.events.FocusRequestDirection.BACKWARD;
				focusManager.moveFocus(direction);
			}
		}
		
	}
}